<template>
  <div class="basic-page file-page">
    <div class="file-detail-dialog">
      <el-page-header @back="back">
        <div slot="content" class="title-wrapper">
          <div>{{ selectedRow.fileOriginalName }}</div>
          <el-row class="el-row-item">
            <el-link v-if="isRenew" icon="el-icon-upload2" @click="handleRenew(selectedRow)">更新版本<el-divider direction="vertical" /></el-link>
            <el-link v-if="isDownload" icon="el-icon-download" @click="handleDownLoad(selectedRow)">下载<el-divider direction="vertical" /></el-link>
            <el-link v-if="isAllUninitiated" icon="el-icon-s-check" @click="handleStart()">发起审核<el-divider direction="vertical" /></el-link>
            <el-link v-if="isAllSign" icon="el-icon-s-check" @click="handleAssign()">签收<el-divider direction="vertical" /></el-link>
            <el-link v-if="isTrack" icon="el-icon-position" @click="handleTrack()">跟踪<el-divider direction="vertical" /></el-link>
            <el-link v-if="isCheck" icon="el-icon-s-check" @click="handleCheck()">审核<el-divider direction="vertical" /></el-link>
            <el-link v-if="isDelegate" icon="el-icon-s-check" @click="handleDelegate()">委派<el-divider direction="vertical" /></el-link>
            <el-link v-if="isDel" icon="el-icon-edit" @click="handleEdit(selectedRow)">重命名<el-divider direction="vertical" /></el-link>
            <el-link v-if="isDel" icon="el-icon-delete" @click="handleDelete(selectedRow.id)">删除</el-link>
          </el-row>
        </div>
      </el-page-header>
    </div>
    <div class="check-box">
      <div class="file-content">
        <preview-page :row="selectedRow" />
        <div class="collapse" @click="isShowRight = !isShowRight"> <i :class="isShowRight ? 'el-icon-caret-right': 'el-icon-caret-left'" /></div>
      </div>
      <transition name="el-fade-in">
        <div v-show="isShowRight" class="detail">
          <el-divider />
          <el-collapse v-model="activeNames">
            <el-collapse-item name="1">
              <template slot="title">
                <span><i class="co-icon-banbenxinxi" />版本信息</span>
              </template>
              <div v-for="(item, index) in historyList" :key="index" :span="24" class="versionWrapper" :class="curVersion === item.id ? 'active' : ''" @click="changeVersion(item)">
                <div>
                  <i v-show="curVersion === item.id" class="el-icon-aim" /><span class="createName">{{ item.createName }} &nbsp;上传 &nbsp;</span><span class="fileName">{{ item.fileOriginalName }}</span>
                </div>
                <div>
                  {{ item.createTime | formatTime }}
                </div>
              </div>
            </el-collapse-item>
            <el-collapse-item name="2">
              <template slot="title">
                <span><i class="el-icon-collection-tag" />标签</span>
              </template>
              <el-tag v-for="tag in dynamicTags" :key="tag" closable :disable-transitions="false" @close="handleClose(tag)">{{ tag }}</el-tag>
              <el-input v-if="inputVisible" ref="saveTagInput" v-model="inputValue" class="input-new-tag" size="small" @keyup.enter.native="handleInputConfirm" @blur="handleInputConfirm" />
              <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 添加标签</el-button>
            </el-collapse-item>
            <el-collapse-item name="4">
              <template slot="title">
                <span><i class="co-icon-shenhe" />审核动态</span>
              </template>
              <el-timeline>
                <el-timeline-item v-for="(activity, index) in checkHistoryList" :key="index" :timestamp="activity.time | formatTime">
                  {{ activity.userId }} 的审批意见：{{ activity.fullMessage }}
                </el-timeline-item>
              </el-timeline>
            </el-collapse-item>
          </el-collapse>
          <el-row v-if="operateStatus === 'check'" class="el-row-item">
            <span><i class="co-icon-shenhe" />附件审核</span>
            <div v-if="checkType !== 'delegate'" style="text-align: center; width: 100%; margin: 20px 0">
              <el-radio-group v-model="checkType">
                <el-radio-button label="complete">通过</el-radio-button>
                <el-radio-button v-if="selectedRow.wsStatus !== 'delegate'" label="reject">驳回</el-radio-button>
                <el-radio-button label="terminate">终止</el-radio-button>
                <el-radio-button label="regress">回退</el-radio-button>
              </el-radio-group>
            </div>
            <div v-if="checkType !== ''">
              <el-form ref="dataFormCheck" :rules="rulesCheck" :model="tempCheck" label-position="right" label-width="90px" style="width: 100%">
                <el-form-item v-if="((checkType === 'complete' && selectedRow.wsStatus !== 'delegate') || checkType === 'delegate') && candidateOptions.assignee !== null && candidateOptions.candidateUsers !== null && candidateOptions.candidateGroups !== null" label="审批人员" prop="candidate">
                  <el-radio-group v-model="radio" @change="changeRadio">
                    <el-radio v-if="candidateOptions.assignee" label="assignee">指定人员</el-radio>
                    <el-radio v-if="candidateOptions.candidateUsers" label="candidateUsers">候选组</el-radio>
                    <el-radio v-if="candidateOptions.candidateGroups" label="candidateGroups">角色人员</el-radio>
                  </el-radio-group>
                  <el-select v-if="radio === 'assignee'" v-model="tempCheck.candidate" placeholder="请选择" class="filter-item" style="width: 100%" disabled>
                    <el-option v-for="(item, index) in candidateOptions.assignee" :key="index" :label="item.nickname" :value="item.username" />
                  </el-select>
                  <el-select v-if="radio === 'candidateUsers'" v-model="tempCheck.candidate" placeholder="请选择" clearable class="filter-item" filterable style="width: 100%">
                    <el-option v-for="(item, index) in candidateOptions.candidateUsers" :key="index" :label="item.nickname" :value="item.username" />
                  </el-select>
                  <el-select v-if="radio === 'candidateGroups'" v-model="tempCheck.candidate" placeholder="请选择" clearable class="filter-item" filterable style="width: 100%">
                    <el-option-group v-for="(group, index) in candidateOptions.candidateGroups" :key="index" :label="group.groupName">
                      <el-option v-for="item in group.userList" :key="item.username" :label="item.nickname" :value="item.username" />
                    </el-option-group>
                  </el-select>
                </el-form-item>
                <el-form-item label="审核意见" prop="comment">
                  <el-input v-model="tempCheck.comment" type="textarea" />
                </el-form-item>
              </el-form>
              <div style="text-align: center">
                <el-button type="primary" @click="checkData()">确 定</el-button>
              </div>
            </div>
          </el-row>
        </div>
      </transition>
    </div>
    <!--更新版本-->
    <el-dialog :close-on-click-modal="false" title="更新附件" :visible.sync="showUpload" width="400px">
      <div>
        <el-upload
          class="upload-demo"
          drag
          :action="uploadAction"
          :headers="uploadHeader"
          :data="uploadRenewData"
          :limit="1"
          :on-success="handleSuccessRenew"
          :on-exceed="handleExceed"
          accept="application/msexcel,application/msword,application/pdf,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document,text/plain,video/*,image/*,.zip"
          :file-list="fileList"
        >
          <i class="el-icon-upload" />
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        </el-upload>
      </div>
      <span slot="footer" class="dialog-footer" />
    </el-dialog>
    <!--发起审核-->
    <el-dialog :close-on-click-modal="false" title="发起审核" :visible.sync="dialogFormVisible" :modal-append-to-body="false" width="1200px">
      <el-steps :active="activeStep" finish-status="success" simple style="margin-top: 20px">
        <el-step title="第一步 选择流程" />
        <el-step title="第二步 选择处理人" />
        <el-step title="第三步 填写信息" />
      </el-steps>
      <el-card shadow="always" style="width: 70%;margin: 30px auto">
        <el-form ref="dataForm" :rules="rules" :model="temp" label-position="right" label-width="90px">
          <el-form-item v-show="activeStep === 1" label="审核流程" prop="processDefinitionId">
            <el-select v-model="temp.processDefinitionId" placeholder="请选择" clearable @change="handleCandidate">
              <el-option
                v-for="item in workFlowOptions"
                :key="item.wbProcDefId"
                :label="item.workflowName"
                :value="item.wbProcDefId"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-show="activeStep === 2" label="审批人员" prop="candidate">
            <el-radio-group v-model="radio" @change="changeRadio">
              <el-radio v-if="candidateOptions.assignee" label="assignee">指定人员</el-radio>
              <el-radio v-if="candidateOptions.candidateUsers" label="candidateUsers">候选组</el-radio>
              <el-radio v-if="candidateOptions.candidateGroups" label="candidateGroups">角色人员</el-radio>
            </el-radio-group>
            <el-select v-if="radio === 'assignee'" v-model="temp.candidate" placeholder="请选择" class="filter-item" style="width: 100%" disabled>
              <el-option v-for="(item, index) in candidateOptions.assignee" :key="index" :label="item.nickname" :value="item.username" />
            </el-select>
            <el-select v-if="radio === 'candidateUsers'" v-model="temp.candidate" placeholder="请选择" clearable class="filter-item" filterable style="width: 100%">
              <el-option v-for="(item, index) in candidateOptions.candidateUsers" :key="index" :label="item.nickname" :value="item.username" />
            </el-select>
            <el-select v-if="radio === 'candidateGroups'" v-model="temp.candidate" placeholder="请选择" clearable class="filter-item" filterable style="width: 100%">
              <el-option-group v-for="(group, index) in candidateOptions.candidateGroups" :key="index" :label="group.groupName">
                <el-option v-for="item in group.userList" :key="item.username" :label="item.nickname" :value="item.username" />
              </el-option-group>
            </el-select>
          </el-form-item>
          <el-form-item v-show="activeStep === 3" label="起止时间" prop="rangeTime">
            <el-date-picker v-model="temp.rangeTime" :picker-options="pickerOptions" type="datetimerange" :default-time="['08:30:00', '18:00:00']" style="width: 100%" clearable />
          </el-form-item>
          <el-form-item v-show="activeStep === 3" label="优先级" prop="priority">
            <el-select v-model="temp.priority" placeholder="请选择">
              <el-option
                v-for="item in priorityOptions"
                :key="item.value"
                :label="item.name"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item v-show="activeStep === 3" label="备注" prop="description">
            <el-input v-model="temp.description" type="textarea" :autosize="{ minRows: 2, maxRows: 4}" placeholder="请输入" />
          </el-form-item>
        </el-form>
        <div v-html="svgSrc" />

      </el-card>
      <div slot="footer" class="dialog-footer">
        <div v-if="activeStep === 1">
          <el-button type="primary" @click="changeStep('next','processDefinitionId')">
            下一步
          </el-button>
        </div>
        <div v-else-if="activeStep === 2">
          <el-button type="primary" @click="changeStep('pre')">
            上一步
          </el-button>
          <el-button type="primary" @click="changeStep('next','candidate')">
            下一步
          </el-button>
        </div>
        <div v-else>
          <el-button @click="dialogFormVisible = false">
            取消
          </el-button>
          <el-button type="primary" @click="startData()">
            确定
          </el-button>
        </div>
      </div>
    </el-dialog>
    <!--跟踪-->
    <el-dialog :close-on-click-modal="false" :visible.sync="trackDialogVisible" :modal-append-to-body="false" width="1200px">
      <div style="width: 1000px; margin: 0 auto" v-html="svgSrc" />
    </el-dialog>
  </div>
</template>

<script>
import * as list from '@/api/getTableList'
import { fileCommand, findSysFileHistoryByFileId } from '@/api/file'
import { getToken } from '@/utils/auth'
import { mapGetters } from 'vuex'
import PreviewPage from '@/componentsMain/Preview/index'
import { downloadCommand } from '@/api/file'
import { saveAs } from 'file-saver'
import { getSysDictByType } from '@/api/admin'
import {
  claimTask,
  findProcessUserTaskByPdId,
  getHighLightedProcessDiagram,
  findWorkflowBusinessByWbPageType,
  queryTaskComment,
  startGeneralReviewProcessInstance,
  findNextTaskUser,
  findCurrTaskUser,
  regressTask,
  completeTask,
  rejectTask,
  terminateTask,
  delegateTask, resolveTask, getProcessResource
} from '@/api/activiti'
export default {
  name: '',
  directives: {
    PreviewPage
  },
  components: {
    PreviewPage
  },
  data() {
    return {
      /* 基础页面参数 */
      searchData: {},
      /* 选择参数 */
      selectionArr: [],
      /* 上传附件及更新版本参数 */
      showUpload: false,
      fileList: [],
      uploadAction: '/api/file/sysfile/fileCommand',
      uploadHeader: { Authorization: 'Bearer ' + getToken() },
      uploadRenewData: { fileBusiness: '', command: 'update', fileStorageId: '', targetId: '' },
      rulesUpload: { fileType: [{ required: true, message: '请选择附件类型！', trigger: 'change' }] },
      synTypeOptions: [],
      /* 审核参数 */
      operateStatus: '',
      selectedRow: {},
      checkType: '',
      tempCheck: {
        candidate: ''
      },
      rulesCheck: {
        checkType: [{ required: true, message: '请选择审核状态！', trigger: 'change' }],
        comment: [{ required: true, message: '请输入审核意见！', trigger: 'change' }]
      },
      /* 历史版本参数 */
      historyList: [],
      activeNames: ['1', '2', '3', '4'],
      curVersion: '',
      /* 标签参数 */
      dynamicTags: ['标签一'],
      inputVisible: false,
      inputValue: '',
      /* 发起审核参数 */
      dialogFormVisible: false,
      priorityOptions: [],
      candidateOptions: [],
      workFlowOptions: [],
      temp: {
        id: undefined,
        candidate: '',
        rangeTime: '',
        priority: '',
        description: '',
        processDefinitionId: ''
      },
      textMap: {
        update: '发起审核',
        create: '新增'
      },
      rules: {
        processDefinitionId: [{ required: true, message: '请选择审核流程！', trigger: 'change' }],
        candidate: [{ required: true, message: '请选择审批人员！', trigger: 'change' }],
        rangeTime: [{ required: true, message: '请选择起止时间！', trigger: 'change' }],
        priority: [{ required: true, message: '请选择优先级！', trigger: 'change' }],
        description: [{ required: true, message: '请填写备注！', trigger: 'change' }]
      },
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() < Date.now() - 8.64e7
        }
      },
      activeStep: 1,
      radio: '',
      /* 历史审核动态参数 */
      checkHistoryList: [],
      /* 跟踪 */
      trackDialogVisible: false,
      svgSrc: '',
      /* drag icon */
      isShowRight: true
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ]),
    isAllUninitiated() {
      const isAll = this.selectionArr.some(info => {
        return !((info.wsStatus === null || info.wsStatus === 'terminated' || info.wsStatus === 'rejected' || info.wsStatus === 'delete') && info.createUsername === this.name && info.fileExtension !== null && (info.fileSource === 'prjmgt' || info.fileSource === 'new_processes' || info.fileSource === 'summary'))
      })
      return !isAll
    },
    isAllSign() {
      const isAll = this.selectionArr.some(info => {
        return (info.wsStatus !== 'sign' || info.wsAssignee !== this.name || info.fileExtension === null)
      })
      return !isAll
    },
    isCheck() {
      const isAll = this.selectionArr.some(info => {
        return ((info.wsStatus === 'pending' || info.wsStatus === 'delegated') && info.wsAssignee === this.name) || ((info.wsStatus === 'delegate' || info.wsStatus === 'rollback') && info.wsDelegator === this.name)
      })
      return isAll
    },
    isDelegate() {
      const isAll = this.selectionArr.some(info => {
        return (info.wsStatus === 'pending' && info.wsAssignee === this.name)
      })
      return isAll
    },
    isTrack() {
      const isAll = this.selectionArr.some(info => {
        return (info.wsStatus === null || info.fileExtension === null || this.selectionArr.length > 1 || info.wsStatus === 'finished' || info.wsStatus === 'terminated')
      })
      return !isAll
    },
    isDel() {
      const isAll = this.selectionArr.some(info => {
        return (info.wsStatus === 'finished') || !(info.fileSource === 'prjmgt' || info.fileSource === 'new_processes' || info.fileSource === 'summary')
      })
      return !isAll
    },
    isDownload() {
      const isAll = this.selectionArr.some(info => {
        return (info.wsStatus === 'finished' || ((info.wsStatus === 'delegate' || info.wsStatus === 'rollback') && (info.wsAssignee === this.name || info.wsOwner === this.name || info.wsDelegator === this.name)) || (info.wsStatus === 'pending' && info.wsAssignee === this.name) || info.createUsername === this.name) || (info.fileSource === 'prjmgt' || info.fileSource === 'new_processes' || info.fileSource === 'summary')
      })
      return isAll
    },
    isRenew() {
      let isAll = false
      if (this.selectedRow.wsStatus === null || this.selectedRow.wsStatus === 'terminated' || this.selectedRow.wsStatus === 'rejected' || this.selectedRow.wsStatus === 'delete') {
        isAll = true
      }
      return isAll
    }
  },
  watch: {
    operateStatus(val) {
      if (val === 'check') {
        this.$nextTick(() => {
          this.$refs['dataFormCheck'].clearValidate()
        })
      }
    }
  },
  created() {
    this.searchData = this.$route.query
    this.getList()
    this.getType()
  },
  methods: {
    back() {
      if (this.$route.query.noGoBack) {
        this.$router.push({ path: '/personaloa/startprocess' })
      } else {
        this.$router.go(-1)
      }
    },
    /* 获取列表信息 */
    getList() {
      list['findFileWorkflowStatusByBusinessId']({ fileBusiness: this.searchData.id }).then(response => {
        this.selectedRow = response.data
        this.selectionArr.push(response.data)
        this.historyList = []
        this.historyList.push(JSON.parse(JSON.stringify(response.data)))
        this.historyList[0].createTime = this.historyList[0].updateTime
        this.curVersion = response.data.id
        this.operateStatus = 'preview'
        this.uploadRenewData.fileBusiness = this.selectedRow.fileBusiness
        this.uploadRenewData.fileStorageId = this.selectedRow.fileFilestorageId
        this.uploadRenewData.targetId = this.selectedRow.id
        this.handleHistoryVersion(response.data.id)
        this.handleCheckHistoryList(response.data)
      })
    },
    getType() {
      getSysDictByType('syn_type').then(response => {
        this.synTypeOptions = response.data
      })
      getSysDictByType('priority').then(response => {
        this.priorityOptions = response.data
      })
    },
    /* 文件功能— */
    handleDownLoad(item) {
      const formData = {
        id: item.id,
        command: 'file'
      }
      downloadCommand(formData).then(response => {
        saveAs(response, item.fileOriginalName)
      })
    },
    /* 发起审核 */
    handleCandidate() {
      findProcessUserTaskByPdId(this.temp.processDefinitionId).then(response => {
        this.candidateOptions = response.data
        if (this.candidateOptions.assignee) {
          this.candidateOptions.assignee = [this.candidateOptions.assignee]
          this.temp.candidate = this.candidateOptions.assignee[0].username
          this.radio = 'assignee'
        } else {
          if (this.candidateOptions.candidateUsers) {
            this.radio = 'candidateUsers'
          } else {
            if (this.candidateOptions.candidateGroups) {
              this.radio = 'candidateGroups'
            } else {
              this.radio = ''
            }
          }
        }
      })
    },
    changeStep(type, field) {
      if (type === 'next') {
        this.$refs['dataForm'].validateField(field, (emailError) => {
          if (!emailError) {
            this.activeStep++
          }
        })
      } else {
        this.activeStep--
      }
    },
    changeRadio(value) {
      if (value === 'assignee') {
        if (this.dialogFormVisible) {
          this.temp.candidate = this.candidateOptions.assignee[0].username
        } else {
          this.tempCheck.candidate = this.candidateOptions.assignee[0].username
        }
      } else {
        this.temp.candidate = ''
        this.tempCheck.candidate = ''
      }
    },
    handleStart(row) {
      this.dialogFormVisible = true
      this.activeStep = 1
      findWorkflowBusinessByWbPageType('file_detail').then(response => {
        this.workFlowOptions = response.data
        if (this.workFlowOptions.length === 1) {
          this.temp.processDefinitionId = this.workFlowOptions[0].wbProcDefId
          this.handleCandidate()
          this.activeStep = 2
          getProcessResource(this.workFlowOptions[0].workflowDeploymentId).then(response => {
            this.svgSrc = response
          })
        }
        this.$nextTick(() => {
          this.$refs['dataForm'].clearValidate()
        })
      })
    },
    // 发起审核
    startData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.startCheck()
        }
      })
    },
    async startCheck() {
      for (let i = 0; i < this.selectionArr.length; i++) {
        const item = this.selectionArr[i]
        await startGeneralReviewProcessInstance({
          candidate: this.temp.candidate,
          priority: this.temp.priority,
          startTime: this.temp.rangeTime ? this.temp.rangeTime[0] : null,
          endTime: this.temp.rangeTime ? this.temp.rangeTime[1] : null,
          description: this.temp.description,
          processDefinitionId: this.temp.processDefinitionId,
          customForm: [],
          businessId: item.fileId
        }).then(() => {
          this.$notify({
            title: '成功',
            message: '发起审核成功',
            type: 'success',
            duration: 2000
          })
        })
      }
      this.dialogFormVisible = false
      this.getList()
    },
    /* 签收 */
    async handleAssign() {
      for (let i = 0; i < this.selectionArr.length; i++) {
        const item = this.selectionArr[i]
        await claimTask(item.wsTaskId).then(response => {
          this.$notify({
            title: '成功',
            message: '签收任务成功',
            type: 'success',
            duration: 2000
          })
        })
      }
      this.getList()
    },
    /* 跟踪 */
    handleTrack() {
      getHighLightedProcessDiagram(this.selectionArr[0].wsProcInstId).then(response => {
        this.svgSrc = response.data
        this.trackDialogVisible = true
      }).catch(() => {
        this.svgSrc = ''
      })
    },
    /* 获取历史版本 */
    handleHistoryVersion(id) {
      findSysFileHistoryByFileId({ id: id }).then(response => {
        if (response.data) {
          this.historyList = [...this.historyList, ...response.data]
          this.historyList[0].createTime = this.historyList[0].updateTime
        }
      })
    },
    /* 获取审核列表 */
    handleCheckHistoryList(row) {
      if (row.wsProcInstId) {
        queryTaskComment({ processInstanceId: row.wsProcInstId }).then(response => {
          this.checkHistoryList = response.data.list
        })
      } else {
        this.checkHistoryList = []
      }
    },
    changeVersion(item) {
      this.curVersion = item.id
      this.selectedRow = Object.assign({}, item) // copy obj
    },
    /* 委派 */
    handleDelegate() {
      this.isShowRight = true
      this.candidateOptions = []
      findCurrTaskUser(this.selectedRow.wsProcInstId).then(response => {
        this.operateStatus = 'check'
        this.candidateOptions = response.data
        if (this.candidateOptions.assignee) {
          this.candidateOptions.assignee = [this.candidateOptions.assignee]
          this.tempCheck.candidate = this.candidateOptions.assignee[0].username
          this.radio = 'assignee'
        } else {
          if (this.candidateOptions.candidateUsers) {
            this.radio = 'candidateUsers'
          } else {
            if (this.candidateOptions.candidateGroups) {
              this.radio = 'candidateGroups'
            } else {
              this.radio = ''
            }
          }
        }
        if (this.candidateOptions.assignee === null && this.candidateOptions.candidateUsers === null && this.candidateOptions.candidateGroups === null) {
          this.tempCheck.candidate = ''
        }
        this.checkType = 'delegate'
      })
    },
    handleCheck() {
      this.candidateOptions = []
      findNextTaskUser(this.selectedRow.wsProcInstId).then(response => {
        this.operateStatus = 'check'
        this.candidateOptions = response.data
        if (this.candidateOptions.assignee) {
          this.candidateOptions.assignee = [this.candidateOptions.assignee]
          this.tempCheck.candidate = this.candidateOptions.assignee[0].username
          this.radio = 'assignee'
        } else {
          if (this.candidateOptions.candidateUsers) {
            this.radio = 'candidateUsers'
          } else {
            if (this.candidateOptions.candidateGroups) {
              this.radio = 'candidateGroups'
            } else {
              this.radio = ''
            }
          }
        }
        if (this.candidateOptions.assignee === null && this.candidateOptions.candidateUsers === null && this.candidateOptions.candidateGroups === null) {
          this.tempCheck.candidate = ''
        }
        this.checkType = 'complete'
      })
    },
    checkData() {
      this.$refs['dataFormCheck'].validate((valid) => {
        if (valid) {
          const tempData = {}
          tempData.taskId = this.selectedRow.wsTaskId
          tempData.comment = this.tempCheck.comment
          tempData.processInstanceId = this.selectedRow.wsProcInstId
          switch (this.checkType) {
            case 'complete':
              if (this.selectedRow.wsStatus === 'delegate') {
                tempData.candidate = this.tempCheck.candidate
                resolveTask(tempData).then(response => {
                  this.handleMessage('处理委派任务成功')
                })
              } else {
                tempData.candidate = this.tempCheck.candidate
                completeTask(tempData).then(response => {
                  this.handleMessage('审核成功')
                })
              }
              break
            case 'reject':
              rejectTask(tempData).then(response => {
                this.handleMessage('驳回任务成功')
              })
              break
            case 'terminate':
              terminateTask(tempData).then(response => {
                this.handleMessage('终止任务成功')
              })
              break
            case 'regress':
              regressTask(tempData).then(response => {
                this.handleMessage('回退任务成功')
              })
              break
            case 'delegate':
              tempData.assignee = this.tempCheck.candidate
              delegateTask(tempData).then(response => {
                this.handleMessage('委派任务成功')
              })
              break
          }
        }
      })
    },
    /* 更新版本&重命名 */
    handleRenew(row) {
      this.fileList = []
      this.showUpload = true
    },
    handleEdit(row) {
      let name = row.fileOriginalName
      if (row.fileExtension !== null) {
        const arr = row.fileOriginalName.split('.')
        arr.splice(arr.length - 1, 1)
        name = arr.join('')
      }
      this.$prompt('请输入文件名', '重命名文件名', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        inputPattern: /\S/,
        inputErrorMessage: '文件名不能为空',
        inputValue: name
      }).then(({ value }) => {
        const formData = new FormData()
        formData.append('fileStorageId', this.selectedRow.fileFilestorageId)
        formData.append('command', 'rename')
        formData.append('targetId', row.id)
        formData.append('fileBusiness', this.selectedRow.fileBusiness)
        formData.append('fileName', value)
        fileCommand(formData).then(response => {
          this.handleMessage('修改成功')
        })
      }).catch(() => {
      })
    },
    /* 删除功能 */
    handleDelete(ids) {
      this.$confirm('此操作将永久删除, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const loading = this.$loading({
          lock: true,
          text: '删除中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        })
        list['deleteCommand'](ids).then(response => {
          this.$notify({
            title: '成功',
            message: '删除成功',
            type: 'success',
            duration: 2000
          })
          this.back()
          loading.close()
        }).catch(() => {
          loading.close()
        })
      })
    },
    /* 上传 */
    handleSuccessRenew(response) {
      if (response.status === 200) {
        this.showUpload = false
        this.getList()
      } else {
        this.fileList = []
        this.handleWarning(response)
      }
    },
    handleExceed() {
      this.handleWarning({ message: '当前限制选择 1 个文件, 您已超出限制' })
    },
    /* 标签功能 */
    handleClose(tag) {
      this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1)
    },

    showInput() {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm() {
      const inputValue = this.inputValue
      if (inputValue) {
        this.dynamicTags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    },
    handleWarning(response) {
      this.$notify({
        title: '警告',
        message: response.message,
        type: 'warning',
        duration: 2000
      })
    },
    handleMessage(message) {
      this.$notify({
        title: '成功',
        message: message,
        type: 'success',
        duration: 2000
      })
      this.operateStatus = 'preview'
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.basic-page{
  padding: 0 20px;
  background: #fff;
  overflow: auto;
  width: 100%;
}

[class^=co-icon-]{
  margin-right: 10px;
  font-size: 24px;
}

.el-divider--horizontal{
  margin: 5px 0 !important;
}
.check-box{
  display: flex;
  .file-content{
    flex: 1;
    height: calc(100vh - 60px);
    overflow: hidden;
    position: relative;
    .collapse{
      position: absolute;
      z-index: 1000;
      font-size: 60px;
      right: 0;
      padding: 130px 20px;
      top: 50%;
      transform: translate(0, -50%);
      color: transparent;
      &:hover{
        color: #FFFFFF;
        background: rgba(0,0,0,0.5);
        border-radius: 5px 0 0 5px;
      }
    }
  }
  .detail{
    width: 800px;
    margin-left: 20px
  }
  .hideDetail{
    width: 0;
    display: none;
  }
}

.title-wrapper{
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 50px;
  text-align: right;
}
.versionWrapper{
  display: flex;
  justify-content: space-between;
  cursor: pointer;
  color: #8c8c8c;
  .el-icon-aim{
    color: #1890ff;
    margin-right: 10px;
    font-size: 16px;
  }
  .createName{
    font-size: 14px;
  }
  .fileName{
    font-size: 12px;
  }
  &:hover{
    color: #000000;
  }
}
.versionWrapper.active{
  color: #000000;
}
.el-tag + .el-tag {
  margin-left: 10px;
}
.button-new-tag {
  margin-left: 10px;
  height: 32px;
  line-height: 30px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
.el-icon-collection-tag{
  margin-right: 10px;
  font-size: 24px;
}
</style>
